package com.example.matrixdemo;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.LogUtils;

public class MainActivity extends AppCompatActivity {
    public TextView textView;
    private static final String TAG = "MatrixLog";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        textView = findViewById(R.id.tv_test);
        textView.setOnClickListener(v -> testThreadAnr());
    }

    private void testThreadAnr() {
        try {
            int number = 0;
            while (number++ < 5) {
                LogUtils.e(TAG, "主线程睡眠导致的ANR:次数" + number + "/5");
                try {
                    Thread.sleep(5000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    LogUtils.e(TAG, "异常信息为:" + e.getMessage());
                }
            }

        } catch (Throwable e) {
            e.printStackTrace();
            LogUtils.e(TAG, "异常信息为:" + e.getMessage());
        }
    }
}